package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IWgtsFansListActivityModel;
import com.wgts.wgts.mvp.presenter.IWgtsFansListActivityPresenter;
import com.wgts.wgts.mvp.view.IWgtsFansListActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.WgtsFansDetail;

import java.util.List;

public class WgtsFansListActivityPresenter implements IWgtsFansListActivityPresenter {

    private IWgtsFansListActivityView view;

    private IWgtsFansListActivityModel model;

    private int pageIndex = 1;

    private int pageSize = 20;

    private String relationLevel;

    private String userRole;

    public WgtsFansListActivityPresenter(IWgtsFansListActivityView view, IWgtsFansListActivityModel model) {
        this.view = view;
        this.model = model;
    }


    @Override
    public void initFansdetail(String relationLevel, String userRole) {
        pageIndex = 1;
        this.relationLevel = relationLevel;
        this.userRole = userRole;
        model.wgtsFansDetail(relationLevel, userRole, String.valueOf(pageIndex), String.valueOf(pageSize), new HttpResultSubscriber<List<WgtsFansDetail>>() {
            @Override
            public void onSuccess(List<WgtsFansDetail> wgtsFansDetails) {
                if(wgtsFansDetails.size() < pageSize){
                    view.initFansDetail(wgtsFansDetails, true);
                }else{
                    view.initFansDetail(wgtsFansDetails, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });

    }

    @Override
    public void moreFansDetal() {
        model.wgtsFansDetail(relationLevel, userRole, String.valueOf(pageIndex), String.valueOf(pageSize), new HttpResultSubscriber<List<WgtsFansDetail>>() {
            @Override
            public void onSuccess(List<WgtsFansDetail> wgtsFansDetails) {
                if(wgtsFansDetails.size() < pageSize){
                    view.moreFansDetail(wgtsFansDetails, true);
                }else{
                    view.moreFansDetail(wgtsFansDetails, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }
}
